package jzqb.controller;

import haha.life.normal.TokenUtils;
import io.swagger.annotations.Api;
import jzqb.annotation.CommentCheck.CommentCheck;
import jzqb.bo.MessageBo;
import jzqb.common.Result;
import jzqb.dao.AdminUserInfoDao;
import jzqb.service.AdminUserInfoService;
import jzqb.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/message")
@Api(tags = "留言板")
public class MessageController {

    @Autowired
    MessageService messageService;

    @Autowired
    AdminUserInfoDao adminUserInfoDao;

    @Autowired
    AdminUserInfoService adminUserInfoService;

    /**
     * message
     *
     * @return
     */
    @CommentCheck
    @PostMapping("/insertMessage")
    public Result insertMessage(@RequestBody MessageBo messageBo, HttpServletRequest request) {
        String userId = TokenUtils.getCurrentUserId(request);
        //  AdminUserPo userInfo = adminUserInfoDao.findUserById(userId);
        messageBo.setPublisher(userId);
        Boolean result = messageService.insertMessage(messageBo);
        if (result) {
            return Result.succ("加入留言信息成功");
        } else {
            return Result.succ("加入留言信息成功失败");
        }
    }

    @PostMapping("/getMessageList")
    public Result getMessageList(@RequestBody MessageBo messageBo, HttpServletRequest httpServletRequest) {
        String userId = TokenUtils.getCurrentUserId(httpServletRequest);
        Result result = messageService.getMessageList(messageBo ,userId);
        return result;
    }

    @PostMapping("/deleteMessage")
    public Result deleteMessage(@RequestBody MessageBo messageBo, HttpServletRequest httpServletRequest) {
        String userId = TokenUtils.getCurrentUserId(httpServletRequest);
        Boolean result = messageService.deleteMessage(messageBo);
        if (result) {
            return Result.succ("删除留言信息成功");
        } else {
            return Result.succ("删除留言信息失败");
        }
    }


}
